<template>
  <!-- 大淘客api下轮播商品库 -->
  <view class="nine_includ_postage">
    <Head title="专题商品" :transparent="false">
      <!-- <text slot="action">搜索</text> -->
    </Head>
    <ItemListComp class="item_box" v-if="questionList.length > 0" :questionList="questionList" :userInfo="userInfo" />
    <view class="cu-load bg-grey" v-if="isLoad" :class="finished?'over':'loading'"></view>
    <ScrollToTop :scrollTop="scrollTop" />
  </view>
</template>

<script>
  import Head from '@/pages/pagecomponents/head'
  import ItemListComp from '@/pages/pagecomponents/itemlist'
  import ScrollToTop from '@/pages/pagecomponents/other/scrolltotop'
  export default {
    components: {
      Head,
      ItemListComp,
      ScrollToTop,
    },
    data() {
      return {
        scrollX: 0, // scroll窗口向左偏移的距离
        questionList: [],
        param: {
          version: 'v1.1.0',
          pageId: 1,
          pageSize: 10,
          topicId: -1, // 通过精选专辑API获取的活动id
        },
        isLoad: false,
        finished: false,
        scrollTop: 0, // 页面滚动高度
      }
    },
    computed:{
      userInfo(){
        return this.$store.state.userInfo
      },
    },
    onPageScroll(e) {
      // 滚动条滚动
      this.scrollTop = e.scrollTop
    },
    onPullDownRefresh() {
      // 下拉刷新
      this.getItemList('pullDown')
    },
    onReachBottom() {
      // 触底函数
      this.nextPaging()
    },
    onLoad(e) {
      this.param.topicId = e.topicId
      this.getItemList()
    },
    methods: {
      nextPaging() {
        // 下一页
        if (this.finished !== true) {
          this.param.pageId += 1
          this.getItemList()
        }
      },
      getItemList(type) {
        if (type === 'pullDown') {
          // 下拉刷新
          this.isLoad = true
          this.questionList = []
          this.param.pageId = 1
        }
        this.$api.dtkapi.topicList(this.param).then(res => {
          if (type === 'pullDown') {
            // 下拉刷新
            uni.stopPullDownRefresh();
          }
          this.isLoad = false
          if (res.data.list && res.data.list.length <= 0) {
            this.finished = true;
          }
          let imgList = res.data.list
          let questionList = this.questionList
          questionList = questionList.concat(imgList)
          this.questionList = questionList
        })
      },
    }
  }
</script>

<style scoped lang="scss">
  .nine_includ_postage {
    position: relative;
    min-height: 100%;
    padding: 80px 0 50upx;
    .item_box {
      // padding: 0 20upx;
      min-height: 800px;
    }
    .cu-load::before {
      content: none
    }
  }
</style>
